// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2023 Yevhen Babiichuk (DustDFG)

#include <DotSort/GameRules/TubeSet.hpp>

#include <cstdint>
#include <vector>

TubeSet::TubeSet(uint8_t tubeSize, uint8_t tubeCount)
	: tubeSize(tubeSize)
	, tubeCount(tubeCount)
	, tubes(tubeCount, Tube(tubeSize))
{
}

bool TubeSet::isPossibleStep(uint8_t t1, uint8_t t2) const
{
	if(this->tubes[t1].isCompleted())
	{
		return false;
	}
	if(this->tubes[t1].isEmpty())
	{
		return false;
	}
	if(this->tubes[t2].isFull())
	{
		return false;
	}
	if(!this->tubes[t2].isSuitableDot(this->tubes[t1].top()))
	{
		return false;
	}
	return true;
}

void TubeSet::doStep(uint8_t t1, uint8_t t2)
{
	this->tubes[t2].push(this->tubes[t1].top());
	this->tubes[t1].pop();
}

const std::vector<uint8_t>& TubeSet::getTube(uint8_t tubeIndex) const
{
	return this->tubes[tubeIndex].getDots();
}
